﻿using Elektronix.Class;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace Elektronix
{
    public partial class _default : System.Web.UI.MasterPage
    {

        ArrayList mr = new ArrayList();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["userID"] != null)
            {
                // sepet durumunu kontrol edicem
                string kuki = "sepet" + Session["userID"].ToString();
                if (Request.Cookies[kuki] != null)
                {
                    siparisler s = new siparisler();
                    s.sepet = Request.Cookies[kuki].Value.ToString();
                    s.sepetiyazdir();
                    lblItems.Text = s.sepetmiktar.ToString();
                    lblPrice.Text = s.sepettutar.ToString();
                }
            }

            rptMarkalar.DataSource = Markalar.markalarigetir();
            rptMarkalar.DataBind();


            if (!IsPostBack)
            {
                Repeater1.DataSource = Elektronix.Class.Markalar.markalarigetir();
                Repeater1.DataBind();

                var c= categories.categorigetir();

                ddlKategoriler.DataSource = c;
                ddlKategoriler.DataTextField = "categoryname";
                ddlKategoriler.DataValueField = "categoryID";
                ddlKategoriler.DataBind();

                //ddlMarkalar.SelectedValue


           
            }




        }




        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Session.Abandon();
        }





        protected void lbMailgroup_Click(object sender, EventArgs e)
        {
            mail m = new mail();
            // m.mailadress = TextBox1.Text;
            m.mail_grubu_ekle();
        }


        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            for (int i = 0; i < Repeater1.Items.Count; i++)
            {

                CheckBox chk = (CheckBox)Repeater1.Items[i].FindControl("chk");
                if (chk.Checked)
                {
                    chk.Checked = true;
                }
                else
                {
                    chk.Checked = false;
                }
            }

        }

        protected void Chk_CheckedChanged(object sender, EventArgs e)
        {

            CheckBox cb = (CheckBox)sender;
            if (cb.Checked)
            {
                //write ur code to insert into database
                cb.Checked = false;
            }
            else
            {
                cb.Checked = true;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            decimal baslangicpara = 0;
            decimal bitispara = 0;
            if (RadioButton1.Checked)
            {
                bitispara = 200;

            }
            else if (RadioButton2.Checked)
            {
                baslangicpara = 200;
                bitispara = 400;

            }
            else if (RadioButton3.Checked)
            {
                baslangicpara = 400;
                bitispara = 600;
            }
            else if (RadioButton4.Checked)
            {
                baslangicpara = 600;
                bitispara = 1000;
            }
            else if (RadioButton5.Checked)
            {
                baslangicpara = 1000;
                bitispara = 1200;
            }

            for (int i = 0; i < Repeater1.Items.Count; i++)
            {

                CheckBox chk = (CheckBox)Repeater1.Items[i].FindControl("chk");
                if (chk.Checked)
                {
                    mr.Add(chk.Text);
                }
            }


            int categoryID =Convert.ToInt32(ddlKategoriler.SelectedValue);

           // 
        
            string icsorgu="";
            for (int i = 0; i < mr.Count; i++)
            {
                if (i !=  mr.Count-1)
                {
                    icsorgu += "brand='" + mr[i].ToString()+ "' or "; 
                }
                else
                {
                    icsorgu += "brand='" + mr[i].ToString()+"'"; 
                }


            }
            string sorgu = "";
            if (bitispara != 1200)
            {
          Session["detaylisorgu"]=sorgu = "select * from products as p inner join resimler as r on p.productID=r.productID where categoryID=" + categoryID.ToString() + " and (price between " + baslangicpara.ToString() + " and " + bitispara.ToString() + ") and ( " + icsorgu + ") ";
            }
            else
            {
         Session["detaylisorgu"] = sorgu = "select * from products as p inner join resimler as r on p.productID=r.productID where categoryID=" + categoryID.ToString() + " and price>=1000 and ( " + icsorgu + ") ";
            }


            Response.Redirect("dproducts.aspx");
        }




    }
}